package poker;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ListIterator;

public class SettingsKaartAchtergrondGUI extends DefaultSettingsPanelGUI {
	Image previewImage;
	ImagePanel drawPanel;
	private SettingsGUI sg;
	
	public SettingsKaartAchtergrondGUI(SettingsGUI sg)
	{
		this.sg = sg;
		setLayout(new BorderLayout());
		previewImage = Toolkit.getDefaultToolkit().getImage("img\\beach.jpg");
		JPanel setPanel1 = new JPanel();
		drawPanel = new ImagePanel(previewImage);
		JLabel setLabel1 = new JLabel("Achterkant kaarten: ");
		JComboBox setBox1 = new JComboBox();
	
	
		String[] backSides = {"Beach", "Desert", "Frog", "Funky", "roze", "skysquare"};
		ComboBoxModel jComboBox1Model = new DefaultComboBoxModel(backSides);
		setBox1.setModel(jComboBox1Model);
		setBox1.addItemListener(new MyItemListener());
		
		setPanel1.add(setLabel1); setPanel1.add(setBox1);
		
		drawPanel.setPreferredSize(new Dimension(200,200));
		drawPanel.add(new JLabel(""));
		add(setPanel1, BorderLayout.NORTH);
		add(drawPanel, BorderLayout.CENTER);
	}
	
	private class ImagePanel extends JPanel
	{
		Image image;
		
		public ImagePanel(Image i)
		{
			this.image = i;
		}
		
		public void paintComponent(Graphics g) 
		{
			super.paintComponent(g);
			if(image != null) 
			{
				g.drawImage(image, 100, 30, this);
			}
		}
	}
	private class MyItemListener implements ItemListener
	{
		public MyItemListener()
		{
			
		}
		
		public void itemStateChanged(ItemEvent ie)
		{
			String imageNaam = ie.getItem().toString();
			SettingsKaartAchtergrondGUI.this.previewImage = Toolkit.getDefaultToolkit().getImage("img\\" + imageNaam +".jpg");
			SettingsKaartAchtergrondGUI.this.drawPanel.image = SettingsKaartAchtergrondGUI.this.previewImage;
			SettingsKaartAchtergrondGUI.this.drawPanel.repaint();
		}
	}
	
	public boolean ok()
	{
		SettingsGUI.getHoofdScherm().backSideCard = previewImage;
		SettingsGUI.getHoofdScherm().repaint();
		return true;
	}
	
	public void cancel()
	{
		
	}
	
}